<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var MyQueue = function () {
            this.inStack = []
            this.outStack = []
        };

        /** 
         * @param {number} x
         * @return {void}
         */
        MyQueue.prototype.push = function (x) {
            this.inStack.push(x)
        };

        /**
         * @return {number}
         */
        MyQueue.prototype.pop = function () {
            if (this.outStack.length > 0 || this.inStack.length > 0) {
                if (this.outStack.length > 0) {
                    let head = this.outStack[0]
                    this.outStack.shift()
                    return head
                } else {
                    for (let i=this.inStack.length-1;i>-1;i--){
                        this.outStack.unshift(this.inStack[i])
                        this.inStack.pop()
                    }
                    let head = this.outStack[0]
                    this.outStack.shift()
                    return head
                }
            }
        };

        /**
         * @return {number}
         */
        MyQueue.prototype.peek = function () {
            if (this.outStack.length > 0 || this.inStack.length > 0) {
                if (this.outStack.length > 0) {
                    return this.outStack[0]
                } else {
                    return this.inStack[0]
                }
            }
        };

        /**
         * @return {boolean}
         */
        MyQueue.prototype.empty = function () {
            return !this.inStack.length&&!this.outStack.length
        };

        var obj = new MyQueue()
        obj.push(1)
        obj.push(2)
        obj.push(3)
        var param_2 = obj.pop()
        console.log(param_2)
        console.log(obj.peek())
        obj.empty()
        console.log(obj)
    </script>
</body>

</html>